API Documentation
Public Member Functions | List of all members
nkMemory::UniquePtr< T > Class Template Reference

Smart pointer owning the object instance it encapsulates. More...

Public Member Functions

 UniquePtr ()
 
 UniquePtr (T *data)
 
template<typename U , typename = std::enable_if_t<std::is_base_of_v<T, U>>>
 UniquePtr (U *data)
 
 UniquePtr (const UniquePtr< T > &other)=delete
 
 UniquePtr (UniquePtr< T > &&other)
 
 ~UniquePtr ()
 
T * get () const
 
bool empty () const
 
void release ()
 
void reset (T *data=nullptr)
 
T & operator* ()
 
const T & operator* () const
 
T * operator-> ()
 
const T * operator-> () const
 
UniquePtr< T > & operator= (const UniquePtr< T > &other)=delete
 
UniquePtr< T > & operator= (UniquePtr< T > &&other)
 
 operator bool () const
 
bool operator! () const
 
 operator std::unique_ptr< T > ()
 
template<typename U , typename = std::enable_if_t<std::is_base_of_v<U, T>>>
 operator std::unique_ptr< U > ()
 
 UniquePtr (std::unique_ptr< T > stdPtr)
 
template<typename U , typename = std::enable_if_t<std::is_base_of_v<T, U>>>
 UniquePtr (std::unique_ptr< U > stdPtr)
 

Detailed Description

template<typename T>
class nkMemory::UniquePtr< T >

Smart pointer owning the object instance it encapsulates.

Globally, this is an equivalent of an std::unique_ptr. However, the aim is not to replace the use of the standard unique pointer in client code, but rather offer a safe way to transfer them to the engine through the method arguments. Its use should be transparent and emulate the way a unique_ptr is normally used.

Constructor & Destructor Documentation

◆ UniquePtr() [1/7]

template<typename T >
nkMemory::UniquePtr< T >::UniquePtr ( )

Empty constructor.

◆ UniquePtr() [2/7]

template<typename T >
nkMemory::UniquePtr< T >::UniquePtr ( T *  data)

Raw pointer constructor.

Parameters
dataThe pointer to take ownership of.
Remarks
The pointer passed will now be owned by the instance of the UniquePtr. As such, it will be deleted at the end of its lifetime.

◆ UniquePtr() [3/7]

template<typename T >
template<typename U , typename = std::enable_if_t<std::is_base_of_v<T, U>>>
nkMemory::UniquePtr< T >::UniquePtr ( U *  data)

Raw pointer constructor, enabled for classes / structures for which the template typename is a base of the passed pointer instance.

Parameters
dataThe pointer to take ownership of.
Remarks
The pointer passed will now be owned by the instance of the UniquePtr. As such, it will be deleted at the end of its lifetime.

◆ UniquePtr() [4/7]

template<typename T >
nkMemory::UniquePtr< T >::UniquePtr ( const UniquePtr< T > &  other)
delete

Copy constructor not allowed, as ownership cannot be shared.

Parameters
other

◆ UniquePtr() [5/7]

template<typename T >
nkMemory::UniquePtr< T >::UniquePtr ( UniquePtr< T > &&  other)

Move constructor.

Parameters
otherThe other pointer to move from.

◆ ~UniquePtr()

template<typename T >
nkMemory::UniquePtr< T >::~UniquePtr ( )

Destructor.

◆ UniquePtr() [6/7]

template<typename T >
nkMemory::UniquePtr< T >::UniquePtr ( std::unique_ptr< T >  stdPtr)

Constructor from a standard unique_ptr implementation.

Parameters
stdPtrThe pointer to move over.

◆ UniquePtr() [7/7]

template<typename T >
template<typename U , typename = std::enable_if_t<std::is_base_of_v<T, U>>>
nkMemory::UniquePtr< T >::UniquePtr ( std::unique_ptr< U >  stdPtr)

Constructor from a standard unique_ptr implementation. Version enabled to support inheritance and conversion to a base type for the contained instance.

Parameters
stdPtrThe pointer to move over.

Member Function Documentation

◆ get()

template<typename T >
T* nkMemory::UniquePtr< T >::get ( ) const
Returns
The instance owned's raw pointer.
Remarks
Given the UniquePtr instance still keeps ownership of the pointer, the client code should not delete the returned pointer.

◆ empty()

template<typename T >
bool nkMemory::UniquePtr< T >::empty ( ) const
Returns
Whether the pointer is nullptr (true) or not (false).

◆ release()

template<typename T >
void nkMemory::UniquePtr< T >::release ( )

Releases the contained instance, along with its ownership, without deleting it.

◆ reset()

template<typename T >
void nkMemory::UniquePtr< T >::reset ( T *  data = nullptr)

Resets the held instance with the one provided as a parameter, deleting the old one in the process.

Parameters
dataThe new pointer to the data to wrap.

◆ operator*() [1/2]

template<typename T >
T& nkMemory::UniquePtr< T >::operator* ( )

Star operator for direct access to the instance.

Returns
A reference over the instance contained.

◆ operator*() [2/2]

template<typename T >
const T& nkMemory::UniquePtr< T >::operator* ( ) const

Star operator for direct access to the instance, const version.

Returns
A const reference over the instance contained.

◆ operator->() [1/2]

template<typename T >
T* nkMemory::UniquePtr< T >::operator-> ( )

Arrow operator for direct access to the instance.

Returns
The underlying pointer to address.

◆ operator->() [2/2]

template<typename T >
const T* nkMemory::UniquePtr< T >::operator-> ( ) const

Arrow operator for direct access to the instance, const version.

Returns
The underlying pointer to address.

◆ operator=() [1/2]

template<typename T >
UniquePtr<T>& nkMemory::UniquePtr< T >::operator= ( const UniquePtr< T > &  other)
delete

Copy assignment operator is unavailable, as ownership can't be shared.

Parameters
other
Returns

◆ operator=() [2/2]

template<typename T >
UniquePtr<T>& nkMemory::UniquePtr< T >::operator= ( UniquePtr< T > &&  other)

Move assignment operator.

Parameters
otherThe other pointer to copy from.
Returns
The reference over the updated calling instance.

◆ operator bool()

template<typename T >
nkMemory::UniquePtr< T >::operator bool ( ) const

Bool conversion operator. Equivalent of the empty method, returning false if the pointer is nullptr, true otherwise.

◆ operator!()

template<typename T >
bool nkMemory::UniquePtr< T >::operator! ( ) const

Not operator, negating the bool conversion operator.

Returns
The negated bool conversion, true if nullptr, false otherwise.

◆ operator std::unique_ptr< T >()

template<typename T >
nkMemory::UniquePtr< T >::operator std::unique_ptr< T > ( )

Conversion operator, to the standard unique_ptr implementation.

◆ operator std::unique_ptr< U >()

template<typename T >
template<typename U , typename = std::enable_if_t<std::is_base_of_v<U, T>>>
nkMemory::UniquePtr< T >::operator std::unique_ptr< U > ( )

Conversion operator, to the standard unique_ptr implementation. Version enabled to support inheritance and conversion to a base type for the contained instance.


The documentation for this class was generated from the following file: